using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml; 

namespace Administration_Toolkit_v2
{
    public partial class ImportResxFiles : Form
    {
        public ImportResxFiles()
        {
            InitializeComponent();
            
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtDirectory.Text == null || txtDirectory.Text == String.Empty)
                {
                    txtStatus.Text = "Please Select a Directory";
                }
                else
                {
                    string DBRootDirectory;
                    DBRootDirectory = Utilities.GetApplicationRootDirectory(cmbApplications.Text); 

                    if(DBRootDirectory.Equals(String.Empty))
                    {
                        Utilities.SetApplicationRootDirectory(cmbApplications.Text, txtDirectory.Text);
                        Utilities.ImportResxFiles(cmbApplications.Text, txtDirectory.Text);
                        txtStatus.Text = "Files Imported";
                    }
                    else if (txtDirectory.Text.Equals(DBRootDirectory))
                    {
                        Utilities.ImportResxFiles(cmbApplications.Text, txtDirectory.Text);
                        txtStatus.Text = "Files Imported";
                    }
                    else
                    {
                        txtStatus.Text = "Directory: " + txtDirectory.Text + " does not equal Root Directory: " + DBRootDirectory;   
                      
                    }
                }
            }
            catch (Exception ex)
            {
                txtStatus.Text = ex.Message;   
            }
        }

        private void ImportResxFiles_Load(object sender, EventArgs e)
        {

            cmbApplications.DataSource = Utilities.GetApplicationList();
            cmbApplications.ValueMember = "ApplicationID";
            cmbApplications.DisplayMember = "ApplicationName"; 
            
        }

        private void btnSelectDirectory_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            txtDirectory.Text = folderBrowserDialog1.SelectedPath;   
        }
    }
}